//
// Created by guoshunw on 2021/2/6.
//

#ifndef AVSTUDY_OGGANALYZER_H
#define AVSTUDY_OGGANALYZER_H

#include "Log.h"
#include <cstdint>
#include <string>

#include <vector>
#include <sstream>
#include <ogg/ogg.h>
#include <opus_types.h>

#include <Utils.h>

using namespace std;

using common::Utils;

class OggAnalyzer {
public:
    explicit OggAnalyzer(const char *file);

    virtual int parse() = 0;

    virtual ~OggAnalyzer();

    static string opusPacketToString(const unsigned char *op, opus_int32 len, int rate = 48000);

    virtual int dumpOpusDataToPcm(const char *outPCMFile = "../resources/ogg/decode.pcm") {
        return -1;
    };

protected:
    const char *_parsingFile{};
};

int testOggAnalyzer(int argc, char *argv[]);


/*
 * Common Ogg structure
 *  OggFile
 *     -----OggPage0
 *         -----header(including how many ogg packets in this packet, each packet is composed by several or one ogg
 *                     segment, the MAX segment size is 255. The last segment size in the packet is less than 255)
 *         -----payload
 *              ----packet0
 *                  ----ogg segment0
 *                  ----ogg segment1
 *                  ....
 *                  ----ogg segmentn
 *              ----packet1
 *              ----packet2
 *              ....
 *              ----packetn
 *     -----OggPage1
 *         -----header
 *         -----payload
 *              ----packet0
 *              ----packet1
 *              ----packet2
 *              ....
 *              ----packetn
 *     -----OggPage2
 *         -----header
 *         -----payload
 *              ----packet0
 *              ----packet1
 *              ----packet2
 *              ....
 *              ----packetn
 *     ......
 *     -----OggPagen
 *         -----header
 *         -----payload
 *              ----packet0
 *              ----packet1
 *              ----packet2
 *              ....
 *              ----packetn
 * */


#endif //AVSTUDY_OGGANALYZER_H
